package NetWork.UDPDome003;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/**
 * ClassName:SendMessage
 * Package:NetWork.UDPDome003
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/7-21:07
 * @Version:v1.0
 */
public class SendMessage {
    public static void main(String[] args) throws IOException {
        /*组播发送端*/

        //创建MulticastSocket对象
        MulticastSocket ms = new MulticastSocket();

        //创建DatagramPacket对象


        String str = "你好,你好";
        byte[]bytes= str.getBytes();
        InetAddress address = InetAddress.getByName("224.0.0.1");
        int port=10086;
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length,address,port);

        //调用MulticastSocket发送数据方法发送数据
        ms.send(dp);

        //释放资源
        ms.close();

    }
}
